<template>
  <view class="container">
    <block v-for="(item,i) in bookList" :key="i">
      <book-item :book="item" @click="gotoBookInfo(item)"></book-item>
    </block>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        bookList: []
      };
    },
    methods: {
      async getBookList(id) {
        const {
          data: data
        } = await uni.$http.get(`/book/list/${id}`)
        if (data.code != 1) return uni.$showMsg()
        this.bookList = data.data
      },
      gotoBookInfo(item) {
        uni.navigateTo({
          url: `/subpkg/book_info/book_info?id=${item.id}&title=${item.title}`
        })
      }
    },
    onLoad(options) {
      const category = decodeURIComponent(options.category);
      this.getBookList(options.id)
      uni.setNavigationBarTitle({
        title: category
      })
    }
  }
</script>

<style lang="scss">
</style>
